/**
 * 时间格式化
 */
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

/**
 * 序列化对象
 * @param {Object} target 目标对象，type必須是 [object Object]
 */
function serializeForm(target) {
    var TYPE_OBJECT = '[object Object]';
    var TYPE_ARRAY = '[object Array]';
    var TYPE_FUNCTION = '[object Function]';
    if(getType(target) !== TYPE_OBJECT){ return target;}
    
    function _isObject(type){
        return type=== TYPE_OBJECT || type === TYPE_ARRAY;
    }
    function getType (value){
        return toString.call(value);
    }
    //递归处理数据
    function recursion(target, key, value) {
        var type = getType(value);
        var __key = key;
        if (type === TYPE_ARRAY) {  __key += '[?]'; } 
        if (type === TYPE_OBJECT) { __key += '.?';  }
        if (type === TYPE_FUNCTION) { return; }

        if (_isObject(type)) {
            for (var _key in value) {
                recursion(target, __key.replace(/\?/g, _key), value[_key]);
            }
            delete target[key];
        } else {
            target[key] = value;
        }
    };

    for (var key in target) {
        recursion.call(this, target, key, target[key]);
    }
    return target;
}